//
//  ReportListModel.m
//
//  Created by  殷聃 on 2019/8/1
//  Copyright (c) 2019 yek. All rights reserved.
//

#import "ReportListModel.h"


NSString *const kReportListModelId = @"id";
NSString *const kReportListModelReportDealUser = @"reportDealUser";
NSString *const kReportListModelEndImg = @"endImg";
NSString *const kReportListModelBeganImg = @"beganImg";
NSString *const kReportListModelReportStatus = @"reportStatus";
NSString *const kReportListModelRepostDealTime = @"repostDealTime";
NSString *const kReportListModelIsDelete = @"isDelete";
NSString *const kReportListModelUserId = @"userId";
NSString *const kReportListModelBeganTime = @"beganTime";
NSString *const kReportListModelEndTime = @"endTime";
NSString *const kReportListModelAddTime = @"addTime";
NSString *const kReportListModelReportResponse = @"reportResponse";


@interface ReportListModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ReportListModel

@synthesize internalBaseClassIdentifier = _internalBaseClassIdentifier;
@synthesize reportDealUser = _reportDealUser;
@synthesize endImg = _endImg;
@synthesize beganImg = _beganImg;
@synthesize reportStatus = _reportStatus;
@synthesize repostDealTime = _repostDealTime;
@synthesize isDelete = _isDelete;
@synthesize userId = _userId;
@synthesize beganTime = _beganTime;
@synthesize endTime = _endTime;
@synthesize addTime = _addTime;
@synthesize reportResponse = _reportResponse;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.internalBaseClassIdentifier = [[self objectOrNilForKey:kReportListModelId fromDictionary:dict] doubleValue];
            self.reportDealUser = [self objectOrNilForKey:kReportListModelReportDealUser fromDictionary:dict];
            self.endImg = [self objectOrNilForKey:kReportListModelEndImg fromDictionary:dict];
            self.beganImg = [self objectOrNilForKey:kReportListModelBeganImg fromDictionary:dict];
            self.reportStatus = [self objectOrNilForKey:kReportListModelReportStatus fromDictionary:dict];
            self.repostDealTime = [self objectOrNilForKey:kReportListModelRepostDealTime fromDictionary:dict];
            self.isDelete = [[self objectOrNilForKey:kReportListModelIsDelete fromDictionary:dict] boolValue];
            self.userId = [self objectOrNilForKey:kReportListModelUserId fromDictionary:dict];
            self.beganTime = [[self objectOrNilForKey:kReportListModelBeganTime fromDictionary:dict] doubleValue];
            self.endTime = [[self objectOrNilForKey:kReportListModelEndTime fromDictionary:dict] doubleValue];
            self.addTime = [[self objectOrNilForKey:kReportListModelAddTime fromDictionary:dict] doubleValue];
            self.reportResponse = [self objectOrNilForKey:kReportListModelReportResponse fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.internalBaseClassIdentifier] forKey:kReportListModelId];
    [mutableDict setValue:self.reportDealUser forKey:kReportListModelReportDealUser];
    [mutableDict setValue:self.endImg forKey:kReportListModelEndImg];
    [mutableDict setValue:self.beganImg forKey:kReportListModelBeganImg];
    [mutableDict setValue:self.reportStatus forKey:kReportListModelReportStatus];
    [mutableDict setValue:self.repostDealTime forKey:kReportListModelRepostDealTime];
    [mutableDict setValue:[NSNumber numberWithBool:self.isDelete] forKey:kReportListModelIsDelete];
    [mutableDict setValue:self.userId forKey:kReportListModelUserId];
    [mutableDict setValue:[NSNumber numberWithDouble:self.beganTime] forKey:kReportListModelBeganTime];
    [mutableDict setValue:[NSNumber numberWithDouble:self.endTime] forKey:kReportListModelEndTime];
    [mutableDict setValue:[NSNumber numberWithDouble:self.addTime] forKey:kReportListModelAddTime];
    [mutableDict setValue:self.reportResponse forKey:kReportListModelReportResponse];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.internalBaseClassIdentifier = [aDecoder decodeDoubleForKey:kReportListModelId];
    self.reportDealUser = [aDecoder decodeObjectForKey:kReportListModelReportDealUser];
    self.endImg = [aDecoder decodeObjectForKey:kReportListModelEndImg];
    self.beganImg = [aDecoder decodeObjectForKey:kReportListModelBeganImg];
    self.reportStatus = [aDecoder decodeObjectForKey:kReportListModelReportStatus];
    self.repostDealTime = [aDecoder decodeObjectForKey:kReportListModelRepostDealTime];
    self.isDelete = [aDecoder decodeBoolForKey:kReportListModelIsDelete];
    self.userId = [aDecoder decodeObjectForKey:kReportListModelUserId];
    self.beganTime = [aDecoder decodeDoubleForKey:kReportListModelBeganTime];
    self.endTime = [aDecoder decodeDoubleForKey:kReportListModelEndTime];
    self.addTime = [aDecoder decodeDoubleForKey:kReportListModelAddTime];
    self.reportResponse = [aDecoder decodeObjectForKey:kReportListModelReportResponse];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeDouble:_internalBaseClassIdentifier forKey:kReportListModelId];
    [aCoder encodeObject:_reportDealUser forKey:kReportListModelReportDealUser];
    [aCoder encodeObject:_endImg forKey:kReportListModelEndImg];
    [aCoder encodeObject:_beganImg forKey:kReportListModelBeganImg];
    [aCoder encodeObject:_reportStatus forKey:kReportListModelReportStatus];
    [aCoder encodeObject:_repostDealTime forKey:kReportListModelRepostDealTime];
    [aCoder encodeBool:_isDelete forKey:kReportListModelIsDelete];
    [aCoder encodeObject:_userId forKey:kReportListModelUserId];
    [aCoder encodeDouble:_beganTime forKey:kReportListModelBeganTime];
    [aCoder encodeDouble:_endTime forKey:kReportListModelEndTime];
    [aCoder encodeDouble:_addTime forKey:kReportListModelAddTime];
    [aCoder encodeObject:_reportResponse forKey:kReportListModelReportResponse];
}

- (id)copyWithZone:(NSZone *)zone
{
    ReportListModel *copy = [[ReportListModel alloc] init];
    
    if (copy) {

        copy.internalBaseClassIdentifier = self.internalBaseClassIdentifier;
        copy.reportDealUser = [self.reportDealUser copyWithZone:zone];
        copy.endImg = [self.endImg copyWithZone:zone];
        copy.beganImg = [self.beganImg copyWithZone:zone];
        copy.reportStatus = [self.reportStatus copyWithZone:zone];
        copy.repostDealTime = [self.repostDealTime copyWithZone:zone];
        copy.isDelete = self.isDelete;
        copy.userId = [self.userId copyWithZone:zone];
        copy.beganTime = self.beganTime;
        copy.endTime = self.endTime;
        copy.addTime = self.addTime;
        copy.reportResponse = [self.reportResponse copyWithZone:zone];
    }
    
    return copy;
}


@end
